<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\Article;
use App\Models\Softdel;
use App\Models\User;
use Illuminate\Http\Request;
use Laravel\Scout\Events\ModelsImported;
use Yansongda\Pay\Pay as PayApp;
use Yansongda\Pay\Log;
use Pay;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware(['auth', 'verified'])->except(['Test', 'Test2', 'Test3']);
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('auth/home');
    }

    //支付测试
    public function Test(Request $request)
    {
        //单支付
//        $order = [
//            'out_trade_no' => '1',
//            'total_amount' => '1',
//            'subject' => 'test subject',
//        ];
//        return Pay::alipay()->web($order);
        //自定义支付
        $config = [
//            'app_id' => '2016082000295641',
            'app_id' => '2018050302626929',
            'notify_url' => 'http://localhost:8084/notify.php',
            'return_url' => 'http://localhost:8084/return.php',
//            'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAuWJKrQ6SWvS6niI+4vEVZiYfjkCfLQfoFI2nCp9ZLDS42QtiL4Ccyx8scgc3nhVwmVRte8f57TFvGhvJD0upT4O5O/lRxmTjechXAorirVdAODpOu0mFfQV9y/T9o9hHnU+VmO5spoVb3umqpq6D/Pt8p25Yk852/w01VTIczrXC4QlrbOEe3sr1E9auoC7rgYjjCO6lZUIDjX/oBmNXZxhRDrYx4Yf5X7y8FRBFvygIE2FgxV4Yw+SL3QAa2m5MLcbusJpxOml9YVQfP8iSurx41PvvXUMo49JG3BDVernaCYXQCoUJv9fJwbnfZd7J5YByC+5KM4sblJTq7bXZWQIDAQAB',
            'ali_public_key' => 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAhQhwi8d86RYGX0J6uYKxGbTzr9d1oW3N7T6zEeu8vlCryYARJ3teSvnr31GtQxmZMu8MJ/3ESpIcohk+MZeJnFl5exGbIEfyscSv8C3MbENZLi4+21DTrR0TueujNr1ru31B/q3zxtm7g0J2uxBgmv82XrbgTn0OZHi5YRNKYXKRoRY+B2NtEXsavbMgvsWfFIdzH9lP84l+fjAn1Sa5NwApSNqwV+ijJesoBFMbsXx4CtnY9Cy6UtBS1V2YT2+GN2uREQzvWUdfEDIxUgXsoOUuzZU551B/t4OXTy6BXFmuCqO8K2WNyZlT1qKaP7uAc5vFR4gBchXC6+gT4GJXwQIDAQAB',
            // 加密方式： **RSA2**
//            'private_key' => 'MIIEpAIBAAKCAQEAs6+F2leOgOrvj9jTeDhb5q46GewOjqLBlGSs/bVL4Z3fMr3p+Q1Tux/6uogeVi/eHd84xvQdfpZ87A1SfoWnEGH5z15yorccxSOwWUI+q8gz51IWqjgZxhWKe31BxNZ+prnQpyeMBtE25fXp5nQZ/pftgePyUUvUZRcAUisswntobDQKbwx28VCXw5XB2A+lvYEvxmMv/QexYjwKK4M54j435TuC3UctZbnuynSPpOmCu45ZhEYXd4YMsGMdZE5/077ZU1aU7wx/gk07PiHImEOCDkzqsFo0Buc/knGcdOiUDvm2hn2y1XvwjyFOThsqCsQYi4JmwZdRa8kvOf57nwIDAQABAoIBAQCw5QCqln4VTrTvcW+msB1ReX57nJgsNfDLbV2dG8mLYQemBa9833DqDK6iynTLNq69y88ylose33o2TVtEccGp8Dqluv6yUAED14G6LexS43KtrXPgugAtsXE253ZDGUNwUggnN1i0MW2RcMqHdQ9ORDWvJUCeZj/AEafgPN8AyiLrZeL07jJz/uaRfAuNqkImCVIarKUX3HBCjl9TpuoMjcMhz/MsOmQ0agtCatO1eoH1sqv5Odvxb1i59c8Hvq/mGEXyRuoiDo05SE6IyXYXr84/Nf2xvVNHNQA6kTckj8shSi+HGM4mO1Y4Pbb7XcnxNkT0Inn6oJMSiy56P+CpAoGBAO1O+5FE1ZuVGuLb48cY+0lHCD+nhSBd66B5FrxgPYCkFOQWR7pWyfNDBlmO3SSooQ8TQXA25blrkDxzOAEGX57EPi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IABYJbiW/M7uhBRsbt8xEygiT0BhtNMV1LeSkCw+30JH8jj6qVZKpGKbkfdvH2HGs1AIP6vbrmEzkXb+v4NX+C8bg18hC/kCgYBDCtAz81TSr04O5FnJ+KFxZUXVunEd//yrmoKL1G0U0b7FVTyXPCC15HWs8QMM5i6dAZV2n8G6DR21Y+c8LmH2Etc0vKqmHtW4LjCZuDksvS1KA9FPvJXHgdW6TQB8T0R2Uca8NAXbOSu/BVJWkF7wh9tm/axzbS5A84EhhiHPKw==',
            'log' => [ // optional
                'file' => './logs/alipay.log',
                'level' => 'info', // 建议生产环境等级调整为 info，开发环境为 debug
                'type' => 'single', // optional, 可选 daily.
                'max_file' => 30, // optional, 当 type 为 daily 时有效，默认 30 天
            ],
            'http' => [ // optional
                'timeout' => 5.0,
                'connect_timeout' => 5.0,
                // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
            ],
//            'mode' => 'dev', // optional,设置此参数，将进入沙箱模式
        ];
        $order = [
            'out_trade_no' => 'T20190903131900',
            'total_amount' => '0.01',
            'subject' => 'test subject - 测试',
        ];
//        $alipay = PayApp::alipay($config)->wap($order);
//        return $alipay->send();
        $q = [
            'out_trade_no' => 'T20190903131900',
            'trade_no' => '',
        ];
//        $res = PayApp::alipay($config)->find('T20190903131900');
        $res = PayApp::alipay($config)->find('T962201903241414374377');
//        $res = PayApp::alipay($config)->find($order);
        return $res;
    }

    //全文搜索测试
    public function Test2(Request $request)
    {
        $search = $request->search;
//        $article = Article::find(2);
//        $article->content = 'ddd';
//        $article->save();

//        Article::where('id', 1)->update([
//            'content' => 'rrr'
//        ]);
//        Article::where('id', '=', 1)->searchable();

//        Article::create([
//            'title' => 'ooo',
//            'content' => 'ooo',
//        ]);

//        Article::insert([
//            'title' => 'mmm',
//            'content' => 'mmm',
//        ]);

//        Article::where('content', 'fff')->delete();
        return Article::search($search)->orderBy('test.keyword')->get();
    }

    //软删除测试
    public function Test3(Request $request)
    {
//        Softdel::where('id',1)->delete();
//        return Softdel::get();
        $user = User::find(1);
        return $user->softdel;
    }
}
